package org.hagopa.games.moneypool.msgs.ContentTypes.game;

import java.nio.ByteBuffer;

import org.hagopa.games.moneypool.game.gameobjects.PropertyStatusEnum;

public class Ustatus {
	private int playerId = 0;
	private int playerCash = 0;
	private int playerPosition = 0;
	private int abId = 0; //absolute Id - independent from Board number
	private int upgradeLevel = 0; // TODO change to Enum
	private int currentCost = 0;
	private int fee = 0;
	private PropertyStatusEnum status = null; 
	private int owner = 0; // player id in current Game
	private int total_size = 0;
	//|plid|new_position|cash_status|abid|upgrade_level|curr_cost|fee|status|owner| 
	
	
	public byte[] marshallToByte() {
		ByteBuffer dataArray = ByteBuffer.allocate(256);
		total_size =  4*9;
		byte [] bytes = new byte[total_size];
		
		dataArray.putInt(this.playerId);
		dataArray.putInt(this.playerPosition);
		dataArray.putInt(this.playerCash);
		dataArray.putInt(this.abId);
		dataArray.putInt(this.upgradeLevel);
		dataArray.putInt(this.currentCost);
		dataArray.putInt(this.fee);
		dataArray.putInt(this.status.idx());
		dataArray.putInt(this.owner);
		
		
		dataArray.rewind();
		dataArray.get(bytes,0,bytes.length);
		return bytes;
	}
	
	public boolean unmarshallFromByte(byte[] content) {
		ByteBuffer dataArray = ByteBuffer.wrap(content);
		if(null == dataArray)
		{
			return false;
		}
		dataArray.clear();
		
		this.playerId = dataArray.getInt();
		this.playerPosition = dataArray.getInt();
		this.playerCash = dataArray.getInt();
		this.abId = dataArray.getInt();
		this.upgradeLevel = dataArray.getInt();
		this.currentCost = dataArray.getInt();
		this.fee = dataArray.getInt();
		this.status = PropertyStatusEnum.getEnum(dataArray.getInt());
		this.owner = dataArray.getInt();
		return true;
	}

	public int getPlayerId() {
		return playerId;
	}

	public void setPlayerId(int playerId) {
		this.playerId = playerId;
	}

	public int getPlayerCash() {
		return playerCash;
	}

	public void setPlayerCash(int playerCash) {
		this.playerCash = playerCash;
	}

	public int getPlayerPosition() {
		return playerPosition;
	}

	public void setPlayerPosition(int playerPosition) {
		this.playerPosition = playerPosition;
	}

	public int getAbId() {
		return abId;
	}

	public void setAbId(int abId) {
		this.abId = abId;
	}

	public int getUpgradeLevel() {
		return upgradeLevel;
	}

	public void setUpgradeLevel(int upgradeLevel) {
		this.upgradeLevel = upgradeLevel;
	}

	public int getCurrentCost() {
		return currentCost;
	}

	public void setCurrentCost(int currentCost) {
		this.currentCost = currentCost;
	}

	public int getFee() {
		return fee;
	}

	public void setFee(int fee) {
		this.fee = fee;
	}

	public PropertyStatusEnum getStatus() {
		return status;
	}

	public void setStatus(PropertyStatusEnum status) {
		this.status = status;
	}

	public int getOwner() {
		return owner;
	}

	public void setOwner(int owner) {
		this.owner = owner;
	}

	public int getTotal_size() {
		return total_size;
	}
}
